package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;


import com.sl.au.entity.Option;
import com.sl.au.repository.OptionRepository;
import com.sl.au.service.OptionService;

@Service("OptionService")
@Transactional
public class OptionServiceImpl extends BaseServiceImpl implements OptionService {
	@Autowired
	OptionRepository optionRepository;

	@Override
	public OptionRepository getRepository() {
		// TODO Auto-generated method stub
		return this.optionRepository;
	}

	@Override
	public List<Option> getOption(int start, int length, String key, String orderName, String dir) {
		Page<Option> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "itemOrder");
		if (StringUtils.hasText(key)) {
			pages = optionRepository.findOption(key, pageable);
		} else {
			pages = optionRepository.findAll(pageable);
		}
		return pages.getContent();
	}

	@Override
	public List<Option> getPage(int start, int length, String key, String orderName, String dir) {
		Page<Option> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
		pages = optionRepository.findAll(pageable);
		return pages.getContent();
	}

	@Override
	public Option findByGroupAndExtended1(String group, String ex) {
		
		return optionRepository.findByGroupAndExtended1(group,ex);
	}

}
